package com.pwt.controller.basicsetting;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.common.ResultPage;
import com.pwt.entity.ProductManage;
import com.pwt.entity.ProductStatistics;
import com.pwt.entity.StatisticsPercent;
import com.pwt.model.ProductManageModel;
import com.pwt.model.StatisticsPercentModel;
import com.pwt.service.ProductStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/1
 */
@RestController
@Tag(name = "设置-统计颜色设置")
public class ProductStatisticsController {

    private ProductStatisticsService productStatisticsService;

    public ProductStatisticsController(ProductStatisticsService productStatisticsService) {
        this.productStatisticsService = productStatisticsService;
    }

//    @GetMapping("statistics-s")
//    @Operation(description = "产品统计颜色列表",summary = "产品统计颜色列表")
//    @Parameters({
//            @Parameter(name = "name",description = "统计颜色名称",required = false),
//            @Parameter(name = "limit",description = "展示数",required = true),
//            @Parameter(name = "page",description = "分页数",required = true)
//    })
//    public ResultPage getList(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "page",required = true) Integer page,
//                              @RequestParam(value = "limit",required = true) Integer limit){
//        return this.productStatisticsService.getList(name,page,limit);
//    }

    @GetMapping("statistics-s")
    @Operation(description = "产品统计颜色列表",summary = "产品统计颜色列表")
    @Parameter(name = "name",description = "统计颜色名称",required = false)
    public List<ProductStatistics> getList(@RequestParam(value = "name",required = false) String name){
        return this.productStatisticsService.getList(name);
    }

    @PostMapping("statistics")
    @Operation(description = "新增统计颜色对象",summary = "新增统计颜色对象")
    public ProductStatistics add(@RequestBody @Validated ProductStatistics productStatistics) throws CustomException {
        return this.productStatisticsService.add(productStatistics);
    }

    @PutMapping("statistics")
    @Operation(description = "修改统计颜色对象",summary = "修改统计颜色对象")
    public ProductStatistics  update(@RequestBody @Validated(value = Update.class) ProductStatistics productStatistics) throws CustomException {
        return this.productStatisticsService.update(productStatistics);
    }

    @DeleteMapping("/statistics/{id}")
    @Operation(description = "删除统计颜色对象根据id",summary = "删除统计颜色对象根据id")
    public void  delete(@Parameter(name = "id", description = "统计颜色对象id")  @PathVariable(required = true) String id) throws CustomException {
        this.productStatisticsService.delete(id);
    }

    @PostMapping("/percent")
    @Operation(description = "设置百分比颜色配置",summary = "设置百分比颜色配置")
    public List<StatisticsPercent> PercentSet(@RequestBody StatisticsPercentModel percentModel) throws CustomException {
        return  this.productStatisticsService.PercentSet(percentModel);
    }

    @GetMapping("/percent/{id}")
    @Operation(description = "获取百分比颜色配置",summary = "获取百分比颜色配置")
    public List<StatisticsPercent> getPercent(@PathVariable(name = "id") String id){
        return this.productStatisticsService.getPercentByStatistics(id);
    }

}
